package easy;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/2/27 13:07
 */
public class RemoveDuplateFromSortedArray {
    public static void main(String[] args) {
        Solution solution = new RemoveDuplateFromSortedArray().new Solution();
        int[] ints = {1, 1, 1, 2, 2, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6};
        System.out.println(solution.removeDuplicates(ints));
    }

    private class Solution {
        public int removeDuplicates(int[] nums) {
            if (nums == null || nums.length == 0) {
                return 0;
            }
            int ready = 1;
            int temp = nums[0];
            for (int i = 1; i < nums.length; i++) {
                if (nums[i] != temp) {
                    temp = nums[i];
                    nums[ready] = temp;
                    ready += 1;
                }
            }
            return ready;
        }
    }
}
